//
//  CarSettingRootViewController.m
//  CPICMobileServiceApp
//
//  Created by sinosoft on 13-2-27.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "CarSettingRootViewController.h"
#import "CarSettingTableViewCell.h"
#import "Config.h"
#import "ASIHTTPRequest.h"
#import "NSString+SBJson.h"
#import "NSObject+SBJson.h"
#import "RCAlertViewUtil.h"
#import "UIImageView+WebCache.h"
#import "IFServiceEvaluation.h"
#import "Appdelegate.h"
#import "WSqlite.h"

@interface CarSettingRootViewController ()

@end

@implementation CarSettingRootViewController
@synthesize TableViewCar;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title=@"车辆设置";
        UIBarButtonItem *rightBtnItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addCarSetting)];
        self.navigationItem.rightBarButtonItem=rightBtnItem;
        //self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    return self;
}

-(void)addCarSetting
{
//    CarAddModifyViewController *carAddModifyViewCtrl=[[CarAddModifyViewController alloc]init];
//    carAddModifyViewCtrl.AddorDetail=YES;
//    [self.navigationController pushViewController:carAddModifyViewCtrl animated:YES];
//    carAddModifyViewCtrl.CarRefreshdelegate=self;
//    [carAddModifyViewCtrl release];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_RIGHT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"车辆信息");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_RIGHT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"车辆信息");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"车辆信息");
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
        
        ADD_RIGHT_BUTTONITEM(@"back.png");
    }

    //添加UITableview
    TableViewCar = [[UITableView alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height-44)];
	TableViewCar.delegate = self;
	TableViewCar.dataSource = self;
    
    TableViewCar.opaque = NO;
    TableViewCar.backgroundView = nil;
    TableViewCar.autoresizingMask = UIViewContentModeTop;
    TableViewCar.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableViewCar.scrollEnabled=YES;
    //TableViewCar.backgroundColor=[UIColor clearColor];
    //[TableViewUser reloadData];
	[self.view addSubview:TableViewCar];
    [self setRequest];
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    myDelegate.bCarsetting=FALSE;
    
    [self setEvaluationRequest];
}

-(void) ClickCallOutBtn
{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    if (myDelegate.bCarsetting==FALSE) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        if ([Flag isEqualToString:@"0"])
        {
            [self IFServiceEvaluation];
            Flag = @"1";
        }
        else
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}

-(void)setEvaluationRequest
{
    NSLog(@"==================");
    NSString *serviceid =@"61301";
    NSString *servicename =@"车辆设置";
    IFServiceEvaluation *ifserviceevaluation =[[IFServiceEvaluation alloc]initView:serviceid withserviceName:servicename];
    [ifserviceevaluation setIfServiceEvaluationRequest];
    [ifserviceevaluation setHidden:YES];
    [self.view addSubview:ifserviceevaluation];
    [ifserviceevaluation release];
}
-(void) IFServiceEvaluation
{
    NSString *serviceid =@"61301";
    NSString *servicename =@"车辆设置";
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    if ([myDefaults stringForKey:serviceid]) {
        NSString *strEvaluate=[myDefaults stringForKey:serviceid];
        if ([strEvaluate isEqualToString:@"1"]) {
            AddServiceEvaluationViewController *serviceevluation = [[AddServiceEvaluationViewController alloc]initView:serviceid withserviceName:servicename];
            [[AppDelegate app].unc pushViewController:serviceevluation animated:YES];
            [serviceevluation release];
        }
        else
        {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }
    else
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

-(void) ClickCallAddBtn
{
    CarAddModifyViewController *carAddModifyViewCtrl=[[CarAddModifyViewController alloc]init];
    carAddModifyViewCtrl.AddorDetail=YES;
    carAddModifyViewCtrl.CarRefreshdelegate=self;
    [self.navigationController pushViewController:carAddModifyViewCtrl animated:YES];
    NSDictionary * dictCustomerInfo =[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CUSTOMER_INFO];
    if (dictCustomerInfo!=nil)
    {
        if ([dictCustomerInfo valueForKey:@"userName"]) {
            carAddModifyViewCtrl.txtPolicyName.text=[dictCustomerInfo valueForKey:@"userName"];
            carAddModifyViewCtrl.txtOwnerName.text=[dictCustomerInfo valueForKey:@"userName"];
            carAddModifyViewCtrl.txtLinceType.text=@"身份证";
            carAddModifyViewCtrl.txtCarNum.text=@"粤B";
            NSLog(@"userName-%@",[dictCustomerInfo valueForKey:@"userName"]);
        }
    }
    else
    {
        
    }
    [carAddModifyViewCtrl release];
}
-(void)RefreshCarRequest
{
    bModify=YES;
    [self setRequest];
}
#pragma UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arrCar count];
}

- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *Identifier=@"Identifier";
    CarSettingTableViewCell *cell=(CarSettingTableViewCell *)[TableViewCar dequeueReusableCellWithIdentifier:Identifier];
    if (cell==nil)
    {
        cell=[[[CarSettingTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.lblCar.font = [UIFont systemFontOfSize:14.0];
    NSMutableDictionary *dictCar=[arrCar objectAtIndex:indexPath.row];
    cell.lblCar.text=[dictCar valueForKey:@"carName"];
    NSString *imgURL=[dictCar valueForKey:@"carIconUrl"];
    imgURL=[imgURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [cell.imgViewShort setImageWithURL:[NSURL URLWithString:imgURL] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
	return cell;
}
//-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    //添加你要删除的内容
//    //[self setDeleteRequest:indexPath.row];
//}
-(void)setDeleteRequest:(NSInteger)index
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
        return;
    }
    
//    NSString *strRequestCode=@"RequestCode=61501";
    NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
    [dicRequest setObject:[[arrCar objectAtIndex:index] objectForKey:@"carID"] forKey:@"carID"];
    [dicRequest setObject:[dictUserInfo valueForKey:@"UserAccount"] forKey:@"userAccount"];
    NSString *strRequestJson=[dicRequest JSONRepresentation];
//    strRequestJson=[NSString stringWithFormat:@"&RequestData=%@",strRequestJson];
//    
//    //strRequestJson=[NSString stringWithFormat:@"&RequestData=%@",strRequestJson];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,strRequestCode,strRequestJson];
//    NSString *strUrlEncod = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    NSURL *myurl = [NSURL URLWithString:strUrlEncod];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"请求报文为:%@",strUrl);
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"61501" forKey:@"RequestCode"];
    [request setPostValue:strRequestJson forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseDeleteFail:)];
    [request setDidFinishSelector:@selector(ResonseDeleteSuccess:)];
    [request startAsynchronous];
    
    
    showProgress = YES;
    if (showProgress) {
        NSLog(@"88888");
       // [NSThread sleepForTimeInterval:1];
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"查询中...";
        [progress show:YES];
        showProgress = NO;
        };
}

- (void)ResonseDeleteSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictHead=[dictResponse valueForKey:@"head"];
    NSString *strResult= [[NSString alloc] initWithFormat:@"%@",[dictHead objectForKey:@"success"]];
    NSLog(@"strResult%@",strResult);
    if ([strResult isEqualToString:@"1"]) {
        [self justShowMessage:@"删除成功" title:nil];
        [self setRequest];
        [TableViewCar reloadData];
    }
    else
    {
        [self justShowMessage:@"删除失败" title:nil];
    }
    [strResult release];
    
}

- (void)ResponseDeleteFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}
//-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return @"删除";
//}
//
//-(BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
//    return YES;
//}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self setDetailRequest:indexPath.row];
}

-(void)setDetailRequest:(NSInteger)index
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
        return;
    }
    strCarID=[[arrCar objectAtIndex:index] objectForKey:@"carID"];
    WSqlite *sql =[WSqlite Instance];
    NSMutableDictionary *dictCarDetail=[sql getCarDetail:strCarID withUserAccount:[dictUserInfo valueForKey:@"UserAccount"]];
    if ([dictCarDetail count]>3) {
        CarAddModifyViewController *carAddModifyViewCtrl=[[CarAddModifyViewController alloc]init];
        carAddModifyViewCtrl.AddorDetail=NO;
        [self.navigationController pushViewController:carAddModifyViewCtrl animated:YES];
        
        carAddModifyViewCtrl.txtCarProduct.text=[dictCarDetail valueForKey:@"manufacturersName"];
        carAddModifyViewCtrl.txtCarBrand.text=[dictCarDetail valueForKey:@"brandName"];
        carAddModifyViewCtrl.txtCarType.text=[dictCarDetail valueForKey:@"typeName"];
        carAddModifyViewCtrl.txtCarNum.text=[dictCarDetail valueForKey:@"license"];
        carAddModifyViewCtrl.txtOwnerName.text=[dictCarDetail valueForKey:@"name"];
        carAddModifyViewCtrl.txtLinceNo.text=[dictCarDetail valueForKey:@"iDNum"];
        carAddModifyViewCtrl.txtFirstDate.text=[dictCarDetail valueForKey:@"firstDate"];
        carAddModifyViewCtrl.txtVolume.text=[dictCarDetail valueForKey:@"volume"];
        
        carAddModifyViewCtrl.strDetailProduct=[dictCarDetail valueForKey:@"manufacturers"];
        carAddModifyViewCtrl.strDetailProductName=[dictCarDetail valueForKey:@"manufacturersName"];
        carAddModifyViewCtrl.strDetailBrand=[dictCarDetail valueForKey:@"brand"];
        carAddModifyViewCtrl.strDetailBrandName=[dictCarDetail valueForKey:@"brandName"];
        carAddModifyViewCtrl.strCarID=[dictCarDetail valueForKey:@"carID"];
        carAddModifyViewCtrl.strCarTypeCode=[dictCarDetail valueForKey:@"type"];
        
        if ([dictCarDetail valueForKey:@"policyHolder"]) {
            carAddModifyViewCtrl.txtPolicyName.text=[dictCarDetail valueForKey:@"policyHolder"];
        }
        if ([dictCarDetail valueForKey:@"idType"]) {
            NSString *stridType=[[NSString alloc]initWithFormat:@"%@",[dictCarDetail valueForKey:@"idType"]];
            if ([stridType isEqualToString:@"1"]) {
                carAddModifyViewCtrl.txtLinceType.text=@"身份证";
            }else if ([stridType isEqualToString:@"2"])
            {
                carAddModifyViewCtrl.txtLinceType.text=@"军官证";
            }else if ([stridType isEqualToString:@"4"])
            {
                carAddModifyViewCtrl.txtLinceType.text=@"护照";
            }else if ([stridType isEqualToString:@"5"])
            {
                carAddModifyViewCtrl.txtLinceType.text=@"居民户口薄";
            }else if ([stridType isEqualToString:@"999"])
            {
                carAddModifyViewCtrl.txtLinceType.text=@"团体其它";
            }else
            {
            }
            carAddModifyViewCtrl.strManufacturerCode1=[dictCarDetail valueForKey:@"manufacturers"];
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                // 耗时的操作
                [carAddModifyViewCtrl setBrandRequest:[dictCarDetail valueForKey:@"manufacturers"]];
                NSString *strName=[dictCarDetail valueForKey:@"brandName"];
                if (strName.length!=0) {
                     [carAddModifyViewCtrl setTypeRequest:[dictCarDetail valueForKey:@"brand"]];
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    
                });
            });
            
        }
        [carAddModifyViewCtrl release];

    }
    else
    {
        NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
        [dicRequest setObject:[[arrCar objectAtIndex:index] objectForKey:@"carID"] forKey:@"carID"];
        [dicRequest setObject:[dictUserInfo valueForKey:@"UserAccount"] forKey:@"userAccount"];
        NSString *strRequestJson=[dicRequest JSONRepresentation];
        ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
        
        //设置需要POST的数据，这里提交两个数据，A=a&B=b
        [request setPostValue:@"61401" forKey:@"RequestCode"];
        [request setPostValue:strRequestJson forKey:@"RequestData"];
        
        [request setDelegate:self];
        [request setDidFailSelector:@selector(ResponseDetailFail:)];
        [request setDidFinishSelector:@selector(ResonseDetailSuccess:)];
        [request startAsynchronous];
        
        
        showProgress = YES;
        if (showProgress) {
            NSLog(@"88888");
            // [NSThread sleepForTimeInterval:1];
            progress= [[MBProgressHUD alloc]initWithView:self.view];
            [self.view addSubview:progress];
            [self.view bringSubviewToFront:progress];
            progress.labelText = @"查询中...";
            [progress show:YES];
            showProgress = NO;
        };
    }
    
}

- (void)ResonseDetailSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictHead=[dictResponse valueForKey:@"head"];
    NSString *strResult= [[NSString alloc] initWithFormat:@"%@",[dictHead objectForKey:@"success"]];
    NSLog(@"strResult%@",strResult);
    if ([strResult isEqualToString:@"1"]) {
        
        WSqlite *sql =[WSqlite Instance];
         NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
        [sql insertCarDetail:dictResponse withCarID:strCarID withUserAccouont:[dictUserInfo valueForKey:@"UserAccount"]];
        
        CarAddModifyViewController *carAddModifyViewCtrl=[[CarAddModifyViewController alloc]init];
        carAddModifyViewCtrl.AddorDetail=NO;
        [self.navigationController pushViewController:carAddModifyViewCtrl animated:YES];
        
        carAddModifyViewCtrl.txtCarProduct.text=[dictResponse valueForKey:@"manufacturersName"];
        carAddModifyViewCtrl.txtCarBrand.text=[dictResponse valueForKey:@"brandName"];
        carAddModifyViewCtrl.txtCarType.text=[dictResponse valueForKey:@"typeName"];
        carAddModifyViewCtrl.txtCarNum.text=[dictResponse valueForKey:@"license"];
        carAddModifyViewCtrl.txtOwnerName.text=[dictResponse valueForKey:@"name"];
        carAddModifyViewCtrl.txtLinceNo.text=[dictResponse valueForKey:@"iDNum"];
        carAddModifyViewCtrl.txtFirstDate.text=[dictResponse valueForKey:@"firstDate"];
        carAddModifyViewCtrl.txtVolume.text=[dictResponse valueForKey:@"volume"];
        
        carAddModifyViewCtrl.strDetailProduct=[dictResponse valueForKey:@"manufacturers"];
        carAddModifyViewCtrl.strDetailProductName=[dictResponse valueForKey:@"manufacturersName"];
        carAddModifyViewCtrl.strDetailBrand=[dictResponse valueForKey:@"brand"];
        carAddModifyViewCtrl.strDetailBrandName=[dictResponse valueForKey:@"brandName"];
        carAddModifyViewCtrl.strCarID=[dictResponse valueForKey:@"carID"];
        carAddModifyViewCtrl.strCarTypeCode=[dictResponse valueForKey:@"type"];
        
        if ([dictResponse valueForKey:@"policyHolder"]) {
            carAddModifyViewCtrl.txtPolicyName.text=[dictResponse valueForKey:@"policyHolder"];
        }
        if ([dictResponse valueForKey:@"idType"]) {
            NSString *stridType=[[NSString alloc]initWithFormat:@"%@",[dictResponse valueForKey:@"idType"]];
            if ([stridType isEqualToString:@"1"]) {
                carAddModifyViewCtrl.txtLinceType.text=@"身份证";
            }else if ([stridType isEqualToString:@"2"])
            {
                carAddModifyViewCtrl.txtLinceType.text=@"军官证";
            }else if ([stridType isEqualToString:@"4"])
            {
               carAddModifyViewCtrl.txtLinceType.text=@"护照";
            }else if ([stridType isEqualToString:@"5"])
            {
               carAddModifyViewCtrl.txtLinceType.text=@"居民户口薄";
            }else if ([stridType isEqualToString:@"999"])
            {
               carAddModifyViewCtrl.txtLinceType.text=@"团体其它";
            }else
            {
            }
            carAddModifyViewCtrl.strManufacturerCode1=[dictResponse valueForKey:@"manufacturers"];
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                // 耗时的操作
                [carAddModifyViewCtrl setBrandRequest:[dictResponse valueForKey:@"manufacturers"]];
                NSString *strName=[dictResponse valueForKey:@"brandName"];
                if (strName.length!=0) {
                    [carAddModifyViewCtrl setTypeRequest:[dictResponse valueForKey:@"brand"]];
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    // 更新界面
                    
                });
            });
            
        }
        [carAddModifyViewCtrl release];
    }
    else
    {
        [self justShowMessage:@"请求失败" title:nil];
    }
    [strResult release];
    
}

- (void)ResponseDetailFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}

-(void)setRequest//向太保移动平台发送请求报文
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
        return;
    }
    
    [arrCar removeAllObjects];
    WSqlite *sql =[WSqlite Instance];
    arrCar=[sql getCarList:[dictUserInfo valueForKey:@"UserAccount"]];
    if ([arrCar count]>0) {
        NSLog(@"%@",arrCar);
        [TableViewCar reloadData];
    }

        NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
        [dicRequest setObject:[dictUserInfo valueForKey:@"UserAccount"] forKey:@"userAccount"];
        NSString *strRequestJson=[dicRequest JSONRepresentation];
        ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
        
        //设置需要POST的数据，这里提交两个数据，A=a&B=b
        [request setPostValue:@"61301" forKey:@"RequestCode"];
        [request setPostValue:strRequestJson forKey:@"RequestData"];
        
        [request setDelegate:self];
        [request setDidFailSelector:@selector(ResponseFail:)];
        [request setDidFinishSelector:@selector(ResonseSuccess:)];
        [request startAsynchronous];
        
        showProgress = YES;
        if (showProgress) {
            NSLog(@"88888");
            //[NSThread sleepForTimeInterval:1];
            progress= [[MBProgressHUD alloc]initWithView:self.view];
            [self.view addSubview:progress];
            [self.view bringSubviewToFront:progress];
            progress.labelText = @"查询中...";
            [progress show:YES];
            showProgress = NO;
        };

}

- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    Flag=@"0";
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    NSMutableDictionary *dictVehicle=[dictResponse objectForKey:@"vehicleSettingInfoList"];
    arrCar=[dictVehicle objectForKey:@"data"];
    NSLog(@"%@",arrCar);
    WSqlite *sql =[WSqlite Instance];
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    [sql insertCarList:arrCar withUserAccount:[dictUserInfo valueForKey:@"UserAccount"]];
    [TableViewCar reloadData];
    
}

- (void)ResponseFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)dealloc
{
    [TableViewCar release];
    [super dealloc];
}

@end
